home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / KMAGV3.ZIP / WAVES.C < prev    next >
C/C++ Source or Header  |  1996-01-11  |  3KB  |  87 lines

  1. //WAVEEXAM.PAS / EXAMPLE FOR A WAVES EFFECT//
  2. //WRITING BY THE KING IN 01/06/96          //
  3.  
  4.  
  5. #include "kmagunit.c"
  6. #include <math.h>
  7. #include <alloc.h>
  8. #define WAVES 3
  9. #define SINWAVES 7
  10. #define PI 3.14159
  11.  
  12. int y,t,t1;
  13. char sinT[360],cosT[360];
  14. unsigned char *Pic;
  15. PaletteType Pal;
  16.  
  17. //-------------------------------------------------//
  18. //        Make a Sin/Cos Tables of Shortint        //
  19. //-------------------------------------------------//
  20. void MakeSinCos()
  21. {
  22. int T;
  23.  
  24.     for(T=0;T<360;T++) {
  25.         sinT[T]=(sin(T*PI/180))*127;
  26.         cosT[T]=(cos(T*PI/180))*127;
  27.     }
  28. }
  29.  
  30. //Paint a vertrical line on the Y
  31. void VLine(int Y,unsigned char Col){
  32.     asm {
  33.         Mov Ax,0x0a000          //Ax = screen segment//
  34.         Mov Es,Ax               //Es = Ax//
  35.         Mov Ax,320              //Ax = 320//
  36.         Mul Y                   //Ax = 320 * Y//
  37.         Mov Di,Ax               //Di = Ax//
  38.         Mov Al,Col              //Al = Col//
  39.         Mov Ah,Col              //Ah = Col//
  40.         Mov Cx,160              //Cx = 160//
  41.         Rep StoSw               //[Es:Di] = Al;[Es:Di+1] = Ah;Inc Di,2//
  42.     }
  43. }
  44. //Draw one line from Where Y1 to Where1 Y//
  45. void DrawVLine(int Y,int Y1,unsigned char *Where,unsigned char *Where1){
  46. asm {
  47.     Cmp Y1,199                  //Checking Ranges On Y1
  48.     Ja Exit
  49.     Cmp Y,199                   //Checking Ranges On Y
  50.     Ja Exit
  51.     Push Ds                     //Saving DS
  52.     Lds Si,Where                //[Ds:Si] = Where
  53.     Mov Ax,320                  //Ax = 320
  54.     Mul Y                       //Ax = Y * 320
  55.     Add Si,Ax                   //Si = Ax
  56.     Les Di,Where1               //[Es:Di] = Where1
  57.     Mov Ax,320                  //Ax = 320
  58.     Mul Y1                      //Ax = Y1 * 320
  59.     Add Di,Ax                   //Di = Ax
  60.     Mov Cx,160                  //Cx = 160
  61.     Rep MovSw                   //[Es:Di] = [Ds:Si];Inc Di,2;Inc Si,2;*320
  62.     Pop Ds                      //Restore Ds
  63. }
  64. Exit:
  65. }
  66.  
  67. void main() {
  68.     Pic = (char *)malloc(64000);
  69.     MakeSinCos();
  70.     SetMode();
  71.     t = 0;
  72.     t1 = 0;
  73.     //Load Picture
  74.     LoadCel("sea.cel",Pic,Pal);
  75.     //Put Pal
  76.     ShowPal(Pal);
  77.     VLine(9,54);
  78.     VLine(181,54);
  79.     do {
  80.         for(y=10;y<=180;y++){
  81.             t = t + WAVES;
  82.             t1 = (sinT[t % 360] * SINWAVES) / 127;
  83.             DrawVLine(t1+y,y,Pic,(unsigned char *)MK_FP(0xa000,0));
  84.         }
  85.         t = t - 170 * WAVES;
  86.     } while(inp(0x60) != 1);
  87. }